<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="../JavaScript/comman.js"></script>
  <style>
    * {
      margin: 0;
      padding: 0;
      list-style-type: none;
      text-decoration: none;
    }
    body {
      width: 100%;
      height: 100%;
    }
    .container {
      width: 1200px;
      margin: 100px auto;
    }
    .wrap {
      position: relative;
    }
    #slide {
      position: relative;
      height: 500px;
      background: #ccc;
    }
    #slide li {
      position: absolute;
    }
    img {
      width: 100%;
      height: 100%;
    }
    .prev, .next {
      font-size: 48px;
      color: aqua;
    }
    .prev {
      float: left;
    }
    .next {
      float: right;
    }
    .arrows {
      position: absolute;
      top: 240px;
      right: 50px;
      bottom: 0;
      left: 50px;
      z-index: 100;
    }
  </style>
    <script>
      window.onload = function () {
        var config = [
          {'width': 400, 'top': 20, 'left':20, 'opacity': 0.2, 'zIndex': 2},
          {'width': 600, 'top': 160, 'left':100, 'opacity': 0.8, 'zIndex': 4},
          {'width': 800, 'top': 240, 'left':200, 'opacity': 1, 'zIndex': 6},
          {'width': 600, 'top': 160, 'left':500, 'opacity': 0.8, 'zIndex': 4},
          {'width': 400, 'top': 20, 'left':780, 'opacity': 0.2, 'zIndex': 2},
        ];
        var ulObj = document.getElementById('slide');
        var list = ulObj.children;
        
        var wrap = my$('wrap');
        var arrows = my$('arrows');
        var arrLeft = my$('arrLeft');
        var arrRight = my$('arrRight');

        //设置标记,只有当动画完成之后，才能点击左右箭头，执行下一次动画。
        var flag = true;
        function assign() {
          for (let i = 0; i < list.length; i++) {
            animate(list[i], config[i], function () {
              flag = true;
            });
          }
        }
        assign();

        arrLeft.onclick = function () {
          if (flag) {
            flag = false;
            config.unshift(config.pop());
            assign();
          }
        };
        arrRight.onclick = function () {
          if (flag) {
            flag = false;
            config.push(config.shift());
            assign();
          }
        };

        wrap.onmouseover = function () {
          animate(arrows,{'opacity':1});
        };
        wrap.onmouseout = function () {
          animate(arrows,{'opacity':0});
        };
      };
    </script>
</head>
<body>
  <div class="container">
    <div class="wrap" id="wrap">
      <ul id="slide">
        <li><a href=""><img src="../images/img/1.png" alt="" /></a></li>
        <li><a href=""><img src="../images/img/2.png" alt="" /></a></li>
        <li><a href=""><img src="../images/img/3.png" alt="" /></a></li>
        <li><a href=""><img src="../images/img/4.png" alt="" /></a></li>
        <li><a href=""><img src="../images/img/5.png" alt="" /></a></li>
      </ul>
      <div class="arrows" id="arrows">
        <a href="javascript:;" class="prev" id="arrLeft"> &lt; </a>
        <a href="javascript:;" class="next" id="arrRight"> &gt; </a>
      </div>
    </div>
  </div>

</body>
</html>